/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace DaveSexton.DocProject.Sandcastle.BuildComponents.TypeConverters.BuiltIn
{
	internal sealed class NestedComponentsPropertyDescriptor : PropertyDescriptor
	{
		#region Public Properties
		public override Type ComponentType
		{
			get
			{
				return context.PropertyDescriptor.ComponentType;
			}
		}

		public override bool IsReadOnly
		{
			get
			{
				return true;
			}
		}

		public override Type PropertyType
		{
			get
			{
				return typeof(SandcastleBuildComponentManager);
			}
		}

		public override string DisplayName
		{
			get
			{
				return displayName;
			}
		}

		public override string Description
		{
			get
			{
				return description;
			}
		}
		#endregion

		#region Private / Protected
		private readonly SandcastleBuildComponentManager manager;
		private readonly string displayName, description;
		private readonly ITypeDescriptorContext context;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="NestedComponentsPropertyDescriptor" /> class.
		/// </summary>
		public NestedComponentsPropertyDescriptor(string name, string displayName, string description, SandcastleBuildComponentManager manager, ITypeDescriptorContext context)
			: base(name, new Attribute[] { new NotifyParentPropertyAttribute(true), new RefreshPropertiesAttribute(RefreshProperties.All) })
		{
			this.displayName = displayName;
			this.description = description;
			this.manager = manager;
			this.context = context;
		}
		#endregion

		#region Methods
		public override bool ShouldSerializeValue(object component)
		{
			return manager.IsDirty;
		}

		public override bool CanResetValue(object component)
		{
			return true;
		}

		public override void ResetValue(object component)
		{
			manager.CancelChanges();
		}

		public override object GetValue(object component)
		{
			return manager;
		}

		public override void SetValue(object component, object value)
		{
			throw new NotSupportedException();
		}
		#endregion
	}
}
